home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP11.ZIP / CHAP11 / HSCHMOO / IOLEOBJ.CPP < prev    next >
C/C++ Source or Header  |  1993-06-16  |  7KB  |  254 lines

  1. /*
  2.  * IOLEOBJ.CPP
  3.  * Schmoo Figure Handler Chapter 11
  4.  *
  5.  * Implementation of the IOleObject interface for Polyline.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include "hschmoo.h"
  18.  
  19.  
  20.  
  21. /*
  22.  * CImpIOleObject::CImpIOleObject
  23.  * CImpIOleObject::~CImpIOleObject
  24.  *
  25.  * Parameters (Constructor):
  26.  *  pObj            LPVOID of the object we're in.
  27.  *  punkOuter       LPUNKNOWN to which we delegate.
  28.  */
  29.  
  30. CImpIOleObject::CImpIOleObject(LPCFigure pObj, LPUNKNOWN punkOuter)
  31.     {
  32.     m_cRef=0;
  33.     m_pObj=pObj;
  34.     m_punkOuter=punkOuter;
  35.     return;
  36.     }
  37.  
  38. CImpIOleObject::~CImpIOleObject(void)
  39.     {
  40.     return;
  41.     }
  42.  
  43.  
  44.  
  45. /*
  46.  * CImpIOleObject::QueryInterface
  47.  * CImpIOleObject::AddRef
  48.  * CImpIOleObject::Release
  49.  *
  50.  * Purpose:
  51.  *  IUnknown members for CImpIOleObject object.
  52.  */
  53.  
  54. STDMETHODIMP CImpIOleObject::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  55.     {
  56.     return m_punkOuter->QueryInterface(riid, ppv);
  57.     }
  58.  
  59.  
  60. STDMETHODIMP_(ULONG) CImpIOleObject::AddRef(void)
  61.     {
  62.     ++m_cRef;
  63.     return m_punkOuter->AddRef();
  64.     }
  65.  
  66. STDMETHODIMP_(ULONG) CImpIOleObject::Release(void)
  67.     {
  68.     --m_cRef;
  69.     return m_punkOuter->Release();
  70.     }
  71.  
  72.  
  73.  
  74. /*
  75.  * The only member function we need to implement in a handler is
  76.  * IOleObject::GetExtent since we know exactly how large our data is.
  77.  * All others can be delegated.
  78.  */
  79.  
  80.  
  81. /*
  82.  * CImpIOleObject::GetExtent
  83.  *
  84.  * Purpose:
  85.  *  Retrieves the size of the object in HIMETRIC units.
  86.  *
  87.  * Parameters:
  88.  *  dwAspect        DWORD of the aspect requested
  89.  *  pszl            LPSIZEL into which to store the size.
  90.  *
  91.  * Return Value:
  92.  *  HRESULT         NOERROR if successful, error code otherwise.
  93.  */
  94.  
  95. STDMETHODIMP CImpIOleObject::GetExtent(DWORD dwAspect, LPSIZEL pszl)
  96.     {
  97.     HDC         hDC;
  98.     int         iXppli, iYppli;
  99.     LPRECT      prc;
  100.  
  101.     /*
  102.      * We can answer for CONTENT/THUMBNAIL, but try the server for others.
  103.      * In addition, always delegate is the server is running since
  104.      * it has a window to define the size.
  105.      */
  106.     if (!((DVASPECT_CONTENT | DVASPECT_THUMBNAIL) & dwAspect)
  107.         || OleIsRunning(m_pObj->m_pDefIOleObject))
  108.         return m_pObj->m_pDefIOleObject->GetExtent(dwAspect, pszl);
  109.  
  110.     /*
  111.      * The size is in the rc field of the POLYLINEDATA structure
  112.      * which we now have to convert to HIMETRIC.
  113.      */
  114.     hDC=GetDC(NULL);
  115.     iXppli=GetDeviceCaps(hDC, LOGPIXELSX);
  116.     iYppli=GetDeviceCaps(hDC, LOGPIXELSY);
  117.  
  118.     prc=&m_pObj->m_pl.rc;
  119.     pszl->cx=(long)MulDiv(HIMETRIC_PER_INCH, (prc->right-prc->left), iXppli);
  120.     pszl->cy=(long)MulDiv(HIMETRIC_PER_INCH, (prc->bottom-prc->top), iYppli);
  121.  
  122.     ReleaseDC(NULL, hDC);
  123.  
  124.     return NOERROR;
  125.     }
  126.  
  127.  
  128. /*
  129.  * CImpIOleObject::DoVerb
  130.  *
  131.  * An example of displaying a message when the local server is not
  132.  * present.  This is a good way to get some free advertising if you
  133.  * allow free redistribution of your handler with documents containing
  134.  * your objects.
  135.  */
  136.  
  137. STDMETHODIMP CImpIOleObject::DoVerb(LONG iVerb, LPMSG pMSG
  138.     , LPOLECLIENTSITE pSite, LONG lIndex, HWND hWnd, LPCRECT prc)
  139.     {
  140.     HRESULT     hr;
  141.  
  142.     hr=m_pObj->m_pDefIOleObject->DoVerb(iVerb, pMSG, pSite, lIndex, hWnd, prc);
  143.  
  144.     if (FAILED(hr))
  145.         {
  146.         MessageBox(hWnd, "Local server not present.\nIf I wanted to make money\nI would put some advertising here."
  147.             , "Schmoo Handler", MB_OK);
  148.         }
  149.  
  150.     return hr;
  151.     }
  152.  
  153.  
  154.  
  155.  
  156.  
  157. STDMETHODIMP CImpIOleObject::SetClientSite(LPOLECLIENTSITE pIOleClientSite)
  158.     {
  159.     return m_pObj->m_pDefIOleObject->SetClientSite(pIOleClientSite);
  160.     }
  161.  
  162. STDMETHODIMP CImpIOleObject::GetClientSite(LPOLECLIENTSITE FAR * ppSite)
  163.     {
  164.     return m_pObj->m_pDefIOleObject->GetClientSite(ppSite);
  165.     }
  166.  
  167. STDMETHODIMP CImpIOleObject::SetHostNames(LPCSTR pszApp, LPCSTR pszObj)
  168.     {
  169.     return m_pObj->m_pDefIOleObject->SetHostNames(pszApp, pszObj);
  170.     }
  171.  
  172. STDMETHODIMP CImpIOleObject::Close(DWORD dwSaveOption)
  173.     {
  174.     return m_pObj->m_pDefIOleObject->Close(dwSaveOption);
  175.     }
  176.  
  177. STDMETHODIMP CImpIOleObject::SetMoniker(DWORD dwWhich, LPMONIKER pmk)
  178.     {
  179.     return m_pObj->m_pDefIOleObject->SetMoniker(dwWhich, pmk);
  180.     }
  181.  
  182. STDMETHODIMP CImpIOleObject::GetMoniker(DWORD dwAssign, DWORD dwWhich
  183.     , LPMONIKER FAR * ppmk)
  184.     {
  185.     return m_pObj->m_pDefIOleObject->GetMoniker(dwAssign, dwWhich, ppmk);
  186.     }
  187.  
  188. STDMETHODIMP CImpIOleObject::InitFromData(LPDATAOBJECT pIDataObject
  189.     , BOOL fCreation, DWORD dw)
  190.     {
  191.     return m_pObj->m_pDefIOleObject->InitFromData(pIDataObject, fCreation, dw);
  192.     }
  193.  
  194. STDMETHODIMP CImpIOleObject::GetClipboardData(DWORD dwReserved
  195.     , LPDATAOBJECT FAR * ppIDataObj)
  196.     {
  197.     return m_pObj->m_pDefIOleObject->GetClipboardData(dwReserved, ppIDataObj);
  198.     }
  199.  
  200. STDMETHODIMP CImpIOleObject::EnumVerbs(LPENUMOLEVERB FAR * ppEnum)
  201.     {
  202.     return m_pObj->m_pDefIOleObject->EnumVerbs(ppEnum);
  203.     }
  204.  
  205. STDMETHODIMP CImpIOleObject::Update(void)
  206.     {
  207.     return m_pObj->m_pDefIOleObject->Update();
  208.     }
  209.  
  210. STDMETHODIMP CImpIOleObject::IsUpToDate(void)
  211.     {
  212.     return m_pObj->m_pDefIOleObject->IsUpToDate();
  213.     }
  214.  
  215. STDMETHODIMP CImpIOleObject::GetUserClassID(LPCLSID pClsID)
  216.     {
  217.     return m_pObj->m_pDefIOleObject->GetUserClassID(pClsID);
  218.     }
  219.  
  220. STDMETHODIMP CImpIOleObject::GetUserType(DWORD dwForm, LPSTR FAR * ppszType)
  221.     {
  222.     return m_pObj->m_pDefIOleObject->GetUserType(dwForm, ppszType);
  223.     }
  224.  
  225. STDMETHODIMP CImpIOleObject::SetExtent(DWORD dwAspect, LPSIZEL pszl)
  226.     {
  227.     return m_pObj->m_pDefIOleObject->SetExtent(dwAspect, pszl);
  228.     }
  229.  
  230. STDMETHODIMP CImpIOleObject::Advise(LPADVISESINK pIAdviseSink, LPDWORD pdwConn)
  231.     {
  232.     return m_pObj->m_pDefIOleObject->Advise(pIAdviseSink, pdwConn);
  233.     }
  234.  
  235. STDMETHODIMP CImpIOleObject::Unadvise(DWORD dwConn)
  236.     {
  237.     return m_pObj->m_pDefIOleObject->Unadvise(dwConn);
  238.     }
  239.  
  240. STDMETHODIMP CImpIOleObject::EnumAdvise(LPENUMSTATDATA FAR * ppEnum)
  241.     {
  242.     return m_pObj->m_pDefIOleObject->EnumAdvise(ppEnum);
  243.     }
  244.  
  245. STDMETHODIMP CImpIOleObject::GetMiscStatus(DWORD dwAspect, LPDWORD pdwStatus)
  246.     {
  247.     return m_pObj->m_pDefIOleObject->GetMiscStatus(dwAspect, pdwStatus);
  248.     }
  249.  
  250. STDMETHODIMP CImpIOleObject::SetColorScheme(LPLOGPALETTE pLP)
  251.     {
  252.     return m_pObj->m_pDefIOleObject->SetColorScheme(pLP);
  253.     }
  254.